﻿Namespace Performance

    Public Class Counter
        Private Declare Function QueryPerformanceCounter Lib "Kernel32" (ByRef lpPerformanceCount As Long) As Boolean
        Private Declare Function QueryPerformanceFrequency Lib "Kernel32" (ByRef lpFrequency As Long) As Boolean

        ''' <summary>
        ''' Gets current timestamp in "highfreq ticks"
        ''' </summary>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Shared Function GetPerfCounter() As Long
            Dim lRet As Long
            QueryPerformanceCounter(lRet)
            Return lRet
        End Function
        ''' <summary>
        ''' Returns time in milliseconds
        ''' </summary>
        ''' <param name="startTick"></param>
        ''' <param name="endTick"></param>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Shared Function GetTime(ByVal startTick As Long, ByVal endTick As Long) As Integer
            Dim lFreq As Long
            QueryPerformanceFrequency(lFreq)
            Return CInt(((endTick - startTick) / lFreq) * 1000)
        End Function
    End Class
End Namespace